package com.wchen.project.zk.curator;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @Desc:   使用 Curator 创建会话
 * @author: cww
 * @DateTime: 2020-01-20 22:14
 */

public class ZooKeeperSessionByCurator {
    public static void main(String[] args) throws Exception {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.newClient("home:2181",
                5000, 3000, retryPolicy);
        client.start();
        Thread.sleep(5000);
    }
}
/**
 当前 sleep 时间 = baseSleepTimeMs * Math.max(1, random.nextInt(1 << (retryCount + 1)))
 随着次数的增加，计算出的 sleep 时间会越来越大，如果 sleep 时间在 maxSleepMs 范围之内，那么
 就使用该 sleep 时间，否则使用 maxSleepMs，另外 maxRetries 参数控制了最大重试次数，避免无限重试
 */